package com.juli.school.app.controller.module;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.juli.school.dao.entity.Pub;
import com.juli.school.service.bo.LoveBo;
import com.juli.school.service.bo.RecBo;
import com.juli.school.service.enums.EnumModule;
import com.juli.school.service.impl.LoveService;
import com.juli.school.service.impl.RecService;
import com.juli.school.utils.core.model.CommonResp;
import com.juli.school.utils.core.model.ListResp;
import com.juli.school.utils.core.model.PageResp;

/**
 * @Description: 爱心捐助控制器
 * @author: Eve
 * @date: 2017/9/2.
 */
@Controller
@RequestMapping("/love")
public class LoveController {
	
	@Resource
	LoveService loveService;
	
	@Resource
	RecService recService;
	
	/**
	 * 添加一条爱心捐助
	 * @param love
	 * @return
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	CommonResp<String> add(LoveBo loveBo) {
		return loveService.add(loveBo);
	}
	
	/**
	 * 修改一条爱心捐助
	 * @param love
	 * @return
	 */
	@RequestMapping("update")
	@ResponseBody
	CommonResp<String> update(LoveBo loveBo) {
		return loveService.update(loveBo);
	}
	
	/**
	 * 删除一条记录
	 * @param snStamp
	 * @return
	 */
	@RequestMapping("delete")
	@ResponseBody
	CommonResp<String> delete(String snStamp, String stuId) {
		return loveService.delete(snStamp, stuId);
	}
	
	@RequestMapping("listPage")
	@ResponseBody
	CommonResp<PageResp<Pub>> listPage(LoveBo loveBo) {
		return loveService.listPage(loveBo);
	}
	
	/**
	 * @Description: 增量查询信息列表
	 * @author gaoxiang
	 * @date 2017年9月16日 下午10:27:17
	 */
	@RequestMapping("/list")
	@ResponseBody CommonResp<ListResp<Pub>> list(LoveBo req) {
		return loveService.list(req);
	}
	
	@RequestMapping("detail")
	@ResponseBody
	CommonResp<LoveBo> detail(LoveBo loveBo) {
		return loveService.detail(loveBo);
	}
	
	@RequestMapping("detailer")
	public String detailer(LoveBo loveBo,ModelMap model){
		model.put("type", EnumModule.Love);
		CommonResp<List<RecBo>> list = recService.list(loveBo.getSnStamp());
		model.put("recs", list.getData());
		model.put("obj",  loveService.detail(loveBo));
		return "/detail/index";
	}
}
